#include "header.h"
char game::getMoveInput()
{
  char input = '+';
  while (input!='w' && input!='a' && input!='s' && input!='d' && static_cast<int>(input)!=27 && input!=' ')
  {
    input = getch();
  }
  return input;
}

void game::movementThink(char in)
{
  switch (in)
  {
    case 'w':
      maps[currentboard].movePlayer(maps[currentboard].playerx,maps[currentboard].playery-1);break;
    case 'a':
      maps[currentboard].movePlayer(maps[currentboard].playerx-1,maps[currentboard].playery);break;
    case 's':
      maps[currentboard].movePlayer(maps[currentboard].playerx,maps[currentboard].playery+1);break;
    case 'd':
      maps[currentboard].movePlayer(maps[currentboard].playerx+1,maps[currentboard].playery);break;
    case ' ':
      menu();break;
  }
  if (static_cast<int>(in)==27)
  {
    playing=false;
    quit = true;
  }
}

void game::menu()
{
  bool inMenu=true;
  while(inMenu)
  {
    cout << Color(white, black) << Clear();
    cout << "1: Inventory" << endl;
    cout << "2: Back to game" << endl;
    cout << "3: Quit" << endl;
  
    switch(getMenuInput())
    {
      case '1':
        invMenu();break;
      case '2':
        maps[currentboard].updateRect(room(0,0,80,25));inMenu=false;break;
      case '3':
        playing=false;quit=true;inMenu=false;break;
    }
  }
}

char game::getMenuInput()
{
  char input = ' ';
  while (input!='1' && input!='2' && input!='3')
  {
    input = getch();
  }
  return input;
}

void game::invMenu()
{
  bool inMenu = true;
  while(inMenu)
  {
    cout << Clear();
    for (int counter=97;counter<117;counter++)
    {
      if (player.inventory[counter-97].name!="Empty")
      {
        cout << static_cast<char>(counter) << ": " << player.inventory[counter-97].name << endl;
      }
    }
    cout << "z: Back to main menu";
    char in = getInvMenuInput();
    switch(in)
    {
      case 'z':
        inMenu=false;break;
      default:
        if(player.inventory[static_cast<int>(in-97)].name!="Empty")
          showInvDetails(static_cast<int>(in-97));
    }
  }
}

char game::getInvMenuInput()
{
  char input = getch();
  while ((static_cast<int>(input)<97 || static_cast<int>(input)>117) && input!='z')
  {
    input = getch();
  }
  return input;
}

void game::showInvDetails(int num)
{
  cout << Clear();
  cout << player.inventory[num].name << endl;
  cout << player.inventory[num].attackName << endl;
  cout << player.inventory[num].power << " attack power" << endl;
  cout << player.inventory[num].defense << " defense power" << endl;
  cout << player.inventory[num].currentDurability << "/" << player.inventory[num].maxDurability << " uses" << endl;
  switch (player.inventory[num].type)
  {
    case force:
      cout << "Force gem" << endl;break;
    case magic:
      cout << "Magic gem" << endl;break;
    case psych:
      cout << "Psych gem" << endl;break;
  }
  switch (player.inventory[num].element)
  {
    case light:
      cout << "Light element" << endl;break;
    case fire:
      cout << "Fire element" << endl;break;
    case water:
      cout << "Water element" << endl;break;
    case air:
      cout << "Air element" << endl;break;
    case elec:
      cout << "Electrical element" << endl;break;
    case ice:
      cout << "Ice element" << endl;break;
    case earth:
      cout << "Earth element" << endl;break;
    case dark:
      cout << "Dark element" << endl;break;
  }
  cout << "Push any key to return to the inventory screen";
  getch();
}
